package hhm.spring.security;

import java.util.List;

import hhm.mybatis.mapper.UserMapper;

import org.apache.ibatis.session.SqlSession;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

public class UserDetailServiceImpl implements UserDetailsService {
	public SqlSession getSqlSessionMySql() {
		return sqlSessionMySql;
	}

	public void setSqlSessionMySql(SqlSession sqlSessionMySql) {
		this.sqlSessionMySql = sqlSessionMySql;
	}

	private SqlSession sqlSessionMySql;

	@Override
	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException {

		// 这里自己操作数据库
		SqlSession mSqlSession = getSqlSessionMySql();
		UserMapper mMapper = mSqlSession.getMapper(UserMapper.class);
		List<hhm.mybatis.pojo.User> userList = mMapper.selectByExample(null);

		return new User(username, "21232f297a57a5a743894a0e4a801fc3", true,
				true, true, true, null);
	}

}
